﻿using IServices;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
using System;
using System.Globalization;
using System.Linq;
using YL.Core.Dto;
using YL.Core.Entity;
using YL.Core.Entity.Fluent.Validation;
using YL.NetCore.Attributes;
using YL.NetCore.NetCoreApp;
using YL.Utils.Extensions;
using YL.Utils.Pub;
using YL.Utils.Table;

namespace Method.SmartMeter.Controllers
{
    public class DeviceFailureDayController : BaseController
    {
        private readonly IMeter_DeviceFailureDayServices _DeviceFailureDayServices;

        public DeviceFailureDayController(IMeter_DeviceFailureDayServices DeviceFailureDayServices)
        {
            _DeviceFailureDayServices = DeviceFailureDayServices;
        }
        //DeviceFailureDay
        [HttpGet]
        [CheckMenu]
        public IActionResult Index()
        {
            return View();
        }

        [HttpPost]
        [OperationLog(LogType = LogType.select)]
        public ContentResult List([FromForm]Bootstrap.BootstrapParams bootstrap)
        {
            var sd = _DeviceFailureDayServices.PageList(bootstrap, UserDtoCache.UserId);
            return Content(sd);
        }

        [HttpPost]
        [OperationLog(LogType = LogType.select)]
        public ContentResult Echart([FromForm]Bootstrap.BootstrapParams bootstrap)
        {
            var sd = _DeviceFailureDayServices.Echart(bootstrap, UserDtoCache.UserId);
            return Content(sd);
        }



        //DeviceFailureDetails
        [HttpGet]
        [CheckMenu]
        public IActionResult DetailIndex()
        {
            if (!string.IsNullOrEmpty(Request.Query["ClientID"]))
            {
                ViewBag.ClientID = Convert.ToInt64(Request.Query["ClientID"]);
            }
            if (!string.IsNullOrEmpty(Request.Query["DateMin"]))
            {
                ViewBag.DateMin = Convert.ToString(Request.Query["DateMin"]);
            }
            if (!string.IsNullOrEmpty(Request.Query["DateMax"]))
            {
                ViewBag.DateMax = Convert.ToString(Request.Query["DateMax"]);
            }
            return View();
        }
        
        [HttpPost]
        [OperationLog(LogType = LogType.select)]
        public ContentResult DetailsList([FromForm]Bootstrap.BootstrapParams bootstrap)
        {
            Int64 ClientID = Convert.ToInt64(Request.Query["ClientID"]);
            var sd = _DeviceFailureDayServices.DetailPageList(bootstrap, ClientID);
            return Content(sd);
        }

        [HttpPost]
        [OperationLog(LogType = LogType.select)]
        public ContentResult DetailsEchart([FromForm]Bootstrap.BootstrapParams bootstrap)
        {
            Int64 ClientID = Convert.ToInt64(Request.Query["ClientID"]);
            var sd = _DeviceFailureDayServices.DetailEchart(bootstrap, ClientID);
            return Content(sd);
        }

    }
}